require(['goSwiper','loading'], function(goSwiper,loading) {
	//获取url中的id参数
	var params = getUrlParams();
	var goodsId = params.id?params.id:"";
	var isFollow;
	
	//应用实例化
	var bsDetail = new Vue({
		el: '#bsDetail',
		data: {
			bannerList: [],
			detailsData: [],
			farmTags:[],
			detailsPics:[],
			yjOk: false,
			lsOk: false,
			wghOk: false,
			tudiOk: false,
			jiuleiOk: false,
			showLoading: false,
			apiUrl: wxUrl + '/v3.2/large/detail',
			fllowUrl: wxUrl + '/v3.2/collection/supplymessage',
			item: {
				params:{
					token: token,
					userToken: userToken,
					goodsId: goodsId
				}
			},
			item2: {
				params:{
					token:token,
					userToken: userToken,
					action: 1,
					supplyId:goodsId
				}
			}
		},
		ready: function() {
	        this.getDetailData();
	    },
		methods: {
			getDetailData: function() {
				this.$http.get(this.apiUrl, this.item)
					.then(function(response) {
						var result = JSON.parse(response.body);
						console.log(result)
						if(result.code !=0){
							popBackVHistory();
							/*goIndexPage();*/
							return;
						}
						
						var detailData = result.data.detail;
						var numArray = detailData.rangeBegin.split(".");
						if(numArray[1] == 00){
							detailData.rangeBegin = numArray[0];
						}
						//商品banner图
						var bannerData = detailData.mainImage;
						this.$set('bannerList', bannerData);
						this.bannerFun();
						//运费标签
						if(detailData.freightCharge == 1){
							detailData.freightCharge = '买家承担';
						}else if(detailData.freightCharge == 2){
							detailData.freightCharge = '卖家承担';
						}else{
							detailData.freightCharge = '协商';
						}
						this.$set('detailsData', detailData);
						//农庄标签 and 商品标签
						this.farmTags = detailData.farmTags;
						var goodstag  = detailData.goodsTags;
						if(goodstag.length == 0){
							$(".zizhi").hide();
						}
						for(var j in goodstag){
							if(goodstag[j] == '有机'){
								this.yjOk = true;
							}else if(goodstag[j] == '绿色'){
								this.lsOk = true;
							}else if(goodstag[j] == '无公害'){
								this.wghOk = true;
							}/*else if(goodstag[j] == '土地认证证明'){
								this.tudiOk = true;
							}else if(goodstag[j] == '酒类经营许可证'){
								this.jiuleiOk = true;
							}*/
						}
						//商品详情图片
						this.detailsPics = detailData.detailsPics;
						this.detailImgFun();
						isFollow = result.data.detail.isFollow;
                        if(isFollow == '0'){
                           $(".footer .keep").html('<span class="footZ foot011"></span><br />收藏');
                        }else if(isFollow == '1'){
                           $(".footer .keep").html('<span class="footZ active011"></span><br />已收藏');
                        }
					},function(response) {
						//errorCallback
					});
			},
			fllowMethod: function(){ // 收藏或取消收藏
				if(vLoginClick()){
					if(isFollow == '0'){
	            		this.item2.params.action = 1;
						this.$http.get(this.fllowUrl, this.item2)
							.then(function(response) {
								var result = JSON.parse(response.body);
								var success =  result.data.success;
		                        if(success){
		                        	promptBox("收藏成功！");
		                            $(".footer .keep").html('<span class="footZ active011"></span><br />已收藏');
		                            isFollow = '1';
		                        }	
							},function(response){
								
							});
					} else {
						this.item2.params.action = 0;
						this.$http.get(this.fllowUrl, this.item2)
							.then(function(response) {
								var result = JSON.parse(response.body);
								var success =  result.data.success;
		                        if(success){
		                        	promptBox("取消收藏！");
		                            $(".footer .keep").html('<span class="footZ foot011"></span><br />收藏');
		                            isFollow = '0';
		                        }	
							},function(response){
								
							});
					}
				}
			},
			bannerFun: function(){ //轮播图
				//动态创建slide
    	    	for(var i = 0; i < this.bannerList.length; i++){
    	    		$('<div class="swiper-slide"><img class="wz_img" src="'+this.bannerList[i]+'" class="wz_bannerImg" alt=""></div>').appendTo('#wz_sWrapper');
    	    	}
//  	    	if(this.bannerList.length > 1){
    	    		//swiper 轮播
	    	    	var swiper = new Swiper('.wz_swiper2', {
	    	    		pagination: '.swiper-pagination',
						paginationType: 'fraction',
					    paginationClickable: true,
					    autoplay: 3000,
					    autoplayDisableOnInteraction: false,
					    centeredSlides: true,
					    loop: true
					});
//  	    	}
    	    	
			},
			detailImgFun: function(){ //商品详情图
				for(var i = 0; i < this.detailsPics.length; i++){
    	    		$('<img src="'+this.detailsPics[i]+'" alt="">').appendTo('#detailImgs');
    	    	}
			},
			goBuying: function(){
				if(vLoginClick()){
					window.location.href = self_base_path + '/bigSupply/submitOrder.html?id=' + this.detailsData.goodsId;
				}
			}
		}
	});
});

// 为可控制返回指定页面所有添加pushState
history.pushState({}, document.title, null);
pushVHistory();
window.addEventListener("popstate", function() {
    // 跳转到订单列表页面
	goBackVHistory();
});